home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_9 / taylor.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  587 b   |  23 lines  |  [MATF/MATL]

  1. function [T,Y] = taylor(f,a,b,ya,m)
  2. % [T,Y] = taylor(f,a,b,ya,m)
  3. % Taylor's solution for y' = f(t,y) with y(a) = ya.
  4. % f  is the function, input.
  5. % a  is the left endpoint, input.
  6. % b  is the right endpoint, input.
  7. % ya is the initial condition, input.
  8. % m  is the number of steps, input.
  9. % T  is the vector of abscissas, output.
  10. % Y  is the vector of ordinates, output.
  11. h = (b - a)/m;
  12. T = zeros(1,m+1);
  13. Y = zeros(1,m+1);
  14. T(1) = a;
  15. Y(1) = ya;
  16. for j=1:m,
  17.   tj = T(j);
  18.   yj = Y(j);
  19.   D = feval('df',tj,yj);
  20.   Y(j+1) = yj + h*(D(1)+h*(D(2)/2+h*(D(3)/6+h*D(4)/24)));
  21.   T(j+1) = a + h*j;
  22. end
  23.